%% Author: zj
%% Created: 2010-3-1
%% Description: 天降彩石协议集
-module(pt_36).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([write/2, read/2]).

%%
%% API Functions
%%

%%%=========================================================================
%%% 解包函数
%%%=========================================================================
%% -----------------------------------------------------------------
%% 36000 挖矿倒计时
%% -----------------------------------------------------------------
read(36000, _R) ->
%% 	io:format("read..34000/\n", []),
	{ok, []};

%%	36001
%%挖矿状态切换
read(36001,<<State:8>>)->
	{ok,[State]};

%% 36002 
%%挖矿请求
read(36002,_R) ->
	{ok,[]};

%% 36004
read(36004,_R) ->
	{ok,[]};
%% -----------------------------------------------------------------
%% 错误处理
%% -----------------------------------------------------------------
read(_Cmd, _R) ->
    {error, no_match}.


%%%=========================================================================
%%% 组包函数
%%%=========================================================================


%% -----------------------------------------------------------------
%% 36000 读取设置信息
%% -----------------------------------------------------------------
write(36000,[State,Time,SceneName]) ->
	BinName = tool:to_binary(SceneName),
	Len = byte_size(BinName),
	{ok,pt:pack(36000,<<State:8,Time:32,Len:16,BinName/binary>>)};

%% 36001
%% 挖矿状态切换
write(36001,[Ret,State,PlayerId]) ->
	{ok,pt:pack(36001,<<Ret:8,State:8,PlayerId:32>>)};

%% 36002
%% 挖矿请求
write(36002,[Ret,State]) ->
	{ok,pt:pack(36002,<<Ret:8,State:8>>)};


%% 36003
%% 批量处理状态切换
write(36003,[PlayerList]) ->
	Len = length(PlayerList),
	BinList =[<<Player_id:32>> || Player_id <-PlayerList],
	Bin = tool:to_binary(BinList),
	{ok,pt:pack(36003,<<Len:16,Bin/binary>>)};

%% 36004
%% 恢复正常状态
write(36004,[Ret]) ->
	{ok,pt:pack(36004,<<Ret:8>>)};

%% -----------------------------------------------------------------
%% 错误处理
%% -----------------------------------------------------------------
write(_Cmd, _R) ->
    {ok, pt:pack(0, <<>>)}.



%%
%% Local Functions
%%

